package com.hymjweb.demo.hymj.master_bill_manage.other_charges.service;

import com.hymjweb.demo.SpringAopUtil;
import com.hymjweb.demo.framework.sys.BaseService;
import com.hymjweb.demo.framework.sys.SysConstant;
import com.hymjweb.demo.framework.util.DataTypeUtil;
import com.hymjweb.demo.hymj.log_manage.aop.annotation.OperationLogger;
import com.hymjweb.demo.hymj.master_bill_manage.other_charges.bean.BMasterBillOtherChargePojo;
import com.hymjweb.demo.hymj.master_bill_manage.other_charges.mapper.BMasterBillOtherChargeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class BMasterBillOtherChargeService extends BaseService {


    @Autowired
    private BMasterBillOtherChargeMapper bMasterBillOtherChargeMapper;

    /**
     * 批量插入航空主单位其他费用
     * @param bMasterBillOtherChargePojos
     * @return
     */
    @Transactional(rollbackFor = {Exception.class})
    public int batchInsert(List<BMasterBillOtherChargePojo> bMasterBillOtherChargePojos) throws Exception {
        if(bMasterBillOtherChargePojos==null || bMasterBillOtherChargePojos.isEmpty()){
            throwException("主单其他费用添加参数错误");
        }
        int affectRows = 0;
        for(BMasterBillOtherChargePojo pojo :bMasterBillOtherChargePojos){
            affectRows += SpringAopUtil.getBean(this.getClass()).insert(pojo);
        }
        return affectRows;

    }

    //@OperationLogger(oper = SysConstant.OPER_ADD, operTitle="主单其他费用-新增" , operMemo = "", classType = BMasterBillOtherChargePojo.class)
    @Transactional(rollbackFor = {Exception.class})
    public int insert(BMasterBillOtherChargePojo otherChargePojo) throws Exception {
        if(otherChargePojo==null){
            throwException("主单其他费用添加参数错误");
        }
        return bMasterBillOtherChargeMapper.insert(otherChargePojo);
    }

    /**
     * 根据主单号查询主单其他费用列表
     * @param masterBillId
     * @return
     */
    public List<BMasterBillOtherChargePojo> queryListByMasterBillId(String masterBillId){
        return  bMasterBillOtherChargeMapper.queryListByMasterBillId(masterBillId);
    }


    @Transactional(rollbackFor = {Exception.class})
    public int deleteByMasterBillId(String masterBillId) throws Exception {
        if(DataTypeUtil.isEmptyStr(masterBillId)){
            throwException("根据主单号删除其他费用参数错误!");
        }
        return bMasterBillOtherChargeMapper.deleteByMasterBillId(masterBillId);
    }

    @Transactional(rollbackFor = {Exception.class})
    public int delete(String id) throws Exception {
        if(DataTypeUtil.isEmptyStr(id)){
           throwException("主单其他费用删除参数错误!");
        }
        return bMasterBillOtherChargeMapper.delete(id);
    }
}
